package com.smartthinking.CICPNL.home.activity;

import java.util.ArrayList;
import java.util.Dictionary;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.smartthinking.CICPNL.R;
import com.smartthinking.CICPNL.home.objects.clsDictionary;
import com.smartthinking.CICPNL.home.xml.saxXML;

public class DirectorioPoneExpo extends Activity {

	public ListView list;
	public ExpoPone_Adapter adapter;
	public ArrayList<Dictionary> Actividades;
	public ProgressDialog progressDialog;
	public int put_log = 1;
	public String where_;

	/**
	 * 1=Ponentes 2=Expositores
	 */
	public void onConfigurationChanged(Configuration newConfig) {
		super.onConfigurationChanged(newConfig);

		// Checks the orientation of the screen
		 
	}
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.ui_directorio_expopone);

		Bundle extras = getIntent().getExtras();
		if (extras != null) {

			// this.put_UserName = extras.getString("PUT_USERNAME");
			put_log = extras.getInt("PUT_LOG");
			 

		}

		
		where_ = clsDictionary.getDctionary().get("eve_idr").toString();
		CargarContenido();

	}

	private void CargarContenido() {
		// TODO Auto-generated method stub
		new AsyncActividades().execute("contenido");

	}

	private class AsyncActividades extends AsyncTask<String, Void, Integer> {

		protected void onPostExecute(Integer in) {

			list = (ListView) findViewById(R.id.list);
			adapter = new ExpoPone_Adapter(Actividades);
			list.setAdapter(adapter);

			list.setTextFilterEnabled(true);

			list.setOnItemClickListener(new OnItemClickListener() {
				public void onItemClick(AdapterView<?> parent, View view,
						int position, long id) {

					// Intent intent = new Intent(DirectorioPoneExpo.this,
					// EventosDetalle.class);
					//
					// clsDictionary.setDctionary(Actividades.get(position));
					//
					// startActivity(intent);

					// finish();

				}
			});
			progressDialog.dismiss();
		}

		protected void onPreExecute() {

			progressDialog = ProgressDialog.show(DirectorioPoneExpo.this, "",
					"Cargando...");
		}

		protected Integer doInBackground(String... urls) {

			String qry_url = null;
			if (put_log == 1) {

				qry_url = getString(R.string.QRY_URL)
						+ Uri.encode("select * from ponentes where eve_idr="
								+ where_);
			} else if (put_log == 1) {

				qry_url = getString(R.string.QRY_URL)
						+ Uri.encode("select * from expositores where eve_idr="
								+ where_);

			}
			saxXML saxparser = new saxXML(qry_url);

			Actividades = saxparser.parse();

			return null;

		}

	}

	public class ExpoPone_Adapter extends BaseAdapter {

		private LayoutInflater inflater = null;
		private ArrayList<Dictionary> data;

		public ExpoPone_Adapter(ArrayList<Dictionary> d) {

			data = d;
			inflater = (LayoutInflater) DirectorioPoneExpo.this
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			// imageLoader = new App_ImageLoader(
			// Eventos.this.getApplicationContext());

		}

		public int getCount() {
			return data.size();
		}

		public Object getItem(int position) {
			return position;
		}

		public long getItemId(int position) {
			return position;
		}

		public class ViewHolder {

			public TextView tvInfo;

		}

		public View getView(int position, View convertView, ViewGroup parent) {
			final int position_ = position;
			View vi = convertView;
			ViewHolder holder;

			if (convertView == null) {

				vi = inflater.inflate(R.layout.ui_directorio_expopone_items,
						null);

				holder = new ViewHolder();

				holder.tvInfo = (TextView) vi
						.findViewById(R.id.tv_directorioexpopone_titulo);

				vi.setTag(holder);

			} else

				holder = (ViewHolder) vi.getTag();

			if (put_log == 1) {
				holder.tvInfo.setText(data.get(position).get("pon_nombre")
						.toString()
						+ " "
						+ data.get(position).get("pon_paterno").toString()
						+ " "
						+ data.get(position).get("pon_materno").toString());
			} else if (put_log == 2) {
				holder.tvInfo.setText(data.get(position).get("exp_nombre")
						.toString());

			}
			return vi;

		}

	}
}
